package com.aopeng.controller;

import com.aopeng.entity.AopengExamination;
import com.aopeng.entity.AopengNavcolumn;
import com.aopeng.mapper.AopengExaminationMapper;
import com.aopeng.mapper.AopengNavcolumnMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * zqh
 * 对栏目的增删改查
 */
@Controller
public class AopengNavcolumnController {
    @Autowired
    private AopengNavcolumnMapper aopengNavcolumnMapper;

    //获取所有的数据
    @RequestMapping("/getAopengNavcolumn")
    public  String getAopengNavcolumn(Model model){
        System.out.println("查询全部");
        List<AopengNavcolumn> aopengNavcolumns = aopengNavcolumnMapper.selectList(null);
        model.addAttribute("getAopengNavcolumn",aopengNavcolumns);
        return "/admin/tables";
    }

    //根据id获取数据
    @RequestMapping("/getAopengNavcolumnById")
    public String getAopengNavcolumnById(AopengNavcolumn aopengNavcolumn,Model model){
        System.out.println("根据id查询");
        //获取前台传过来的数据
        AopengNavcolumn getAopengNavcolumnById = aopengNavcolumnMapper.selectById(aopengNavcolumn.getId());
        model.addAttribute("getAopengNavcolumnById",getAopengNavcolumnById);
        return "/admin/updata-tables";
    }

    //根据id修改数据
    @RequestMapping("/updateAopengNavcolumnById")
    public String updateAopengNavcolumnById(AopengNavcolumn aopengNavcolumn){
        System.out.println("根据id修改数据");
        System.out.println(aopengNavcolumn);
        //获取前台传过来的数据修改
        aopengNavcolumnMapper.updateById(aopengNavcolumn);
        return "redirect:/getAopengNavcolumn";
    }

    //增加数据
    @RequestMapping("/insertAopengNavcolumnById")
    public void insertAopengNavcolumnById(){
        System.out.println("增加数据");
        AopengNavcolumn aopengNavcolumn = new AopengNavcolumn();
        int i = aopengNavcolumnMapper.insert(aopengNavcolumn);
        System.out.println(i);
    }

    //根据id删除
    @RequestMapping("/deleteAopengNavcolumnById")
    public String deleteAopengNavcolumnById(AopengNavcolumn aopengNavcolumn){
        System.out.println("根据id删除数据"+aopengNavcolumn.getId());
        aopengNavcolumnMapper.deleteById(aopengNavcolumn.getId());
        return "redirect:/getAopengNavcolumn";
    }
}
